using System;
using NUnit.Framework;

namespace OSC.Base.Tests
{
    [TestFixture]
    public class PersonTests
    {
        private PersonConverter m_PersonConverter = new PersonConverter();

        [Test]
        public void TestFoo()
        {
            var userID = "p.UserId";
            var address = "p.Address";
            var cell = "p.Cell";
            var city = "p.Cell";
            var company = "p.Company";
            var countryOrRegion = "p.CountryOrRegion";
            var fileAs = "p.FileAs";
            var firstName = "p.FirstName";
            var friendStatus = "p.FriendStatus";
            var fullName = "p.FullName";
            var gender = "p.Gender";
            var homePhone = "p.HomePhone";
            var lastName = "p.LastName";
            var nickname = "p.Nickname";
            var phone = "p.Phone";
            var pictureUrl = "p.PictureUrl";
            var relationship = "p.Relationship";
            var state = "p.State";
            var title = "p.Title";
            var webProfilePage = "p.WebProfilePage";
            var workPhone = "p.WorkPhone";
            var zip = "p.Zip";
            var person = new Person
                             {
                                 UserId = userID,
                                 Address = address,
                                 Cell = cell,
                                 City = city,
                                 Company = company,
                                 CountryOrRegion = countryOrRegion,
                                 FileAs = fileAs,
                                 FirstName = firstName,
                                 FriendStatus = friendStatus,
                                 FullName = fullName,
                                 Gender = gender,
                                 HomePhone = homePhone,
                                 LastName = lastName,
                                 Nickname = nickname,
                                 Phone = phone,
                                 PictureUrl = pictureUrl,
                                 Relationship = relationship,
                                 State = state,
                                 Title = title,
                                 WebProfilePage = webProfilePage,
                                 WorkPhone = workPhone,
                                 Zip = zip
                             };
            var result = m_PersonConverter.Convert(person);
            Assert.AreEqual(userID, result.userID);
            Assert.AreEqual(address, result.address);
            Assert.AreEqual(cell, result.cell);
            Assert.AreEqual(city, result.city);
            Assert.AreEqual(company, result.company);
            Assert.AreEqual(countryOrRegion, result.countryOrRegion);
            Assert.AreEqual(fileAs, result.fileAs);
            Assert.AreEqual(firstName, result.firstName);
            Assert.AreEqual(friendStatus, result.friendStatus);
            Assert.AreEqual(fullName, result.fullName);
            Assert.AreEqual(gender, result.gender);
            Assert.AreEqual(homePhone, result.homePhone);
            Assert.AreEqual(lastName, result.lastName);
            Assert.AreEqual(nickname, result.nickname);
            Assert.AreEqual(phone, result.phone);
            Assert.AreEqual(pictureUrl, result.pictureUrl);
            Assert.AreEqual(relationship, result.relationship);
            Assert.AreEqual(state, result.state);
            Assert.AreEqual(title, result.title);
            Assert.AreEqual(webProfilePage, result.webProfilePage);
            Assert.AreEqual(workPhone, result.workPhone);
            Assert.AreEqual(zip, result.zip);
        }

        [Test]
        public void TestConvertPerson_SetsNullDatesNotSpecified()
        {
            DateTime? nullTime = null;
            var person = new Person
                             {
                                 ExpirationTime = nullTime,
                                 LastModificationTime = nullTime,
                                 Anniversary = nullTime,
                                 Birthday = nullTime
                             };
            var result = m_PersonConverter.Convert(person);
            Assert.IsFalse(result.expirationTimeSpecified);
            Assert.IsFalse(result.lastModificationTimeSpecified);
            Assert.IsFalse(result.anniversarySpecified);
            Assert.IsFalse(result.birthdaySpecified);
        }

        [Test]
        public void TestConvertPerson_SetsDatesCorrectly()
        {
            var expirationTime = DateTime.Now.AddDays(-1);
            var lastModificationTime = DateTime.Now.AddDays(-2);
            var anniversary = DateTime.Now.AddDays(-3);
            var birthday = DateTime.Now.AddDays(-4);

            var person = new Person
            {
                ExpirationTime = expirationTime,
                LastModificationTime = lastModificationTime,
                Anniversary = anniversary,
                Birthday = birthday
            };
            var result = m_PersonConverter.Convert(person);
            Assert.AreEqual(expirationTime, result.expirationTime);
            Assert.AreEqual(lastModificationTime, result.lastModificationTime);
            Assert.AreEqual(anniversary, result.anniversary);
            Assert.AreEqual(birthday, result.birthday);
            Assert.IsTrue(result.expirationTimeSpecified);
            Assert.IsTrue(result.lastModificationTimeSpecified);
            Assert.IsTrue(result.anniversarySpecified);
            Assert.IsTrue(result.birthdaySpecified);
        }
        [Test]
        public void TestConvertPerson_SetsNullIndexNotSpecified()
        {
            int? index = null;
            var person = new Person { Index = index };
            var result = m_PersonConverter.Convert(person);
            Assert.IsFalse(result.indexSpecified);
        }
        [Test]
        public void TestConvertPerson_SetsIndexSpecified()
        {
            int? index = 1;
            var person = new Person { Index = index };
            var result = m_PersonConverter.Convert(person);
            Assert.IsTrue(result.indexSpecified);
            Assert.AreEqual(index, result.index);
        }
        [Test]
        public void TestConvertPerson_AllEmailAddresses()
        {
            var emailAddresses = new[] { "first", "second", "third" };
            var person = new Person {};
            Array.ForEach(emailAddresses, person.EmailAddresses.Add);
            var result = m_PersonConverter.Convert(person);

            Assert.AreEqual("first", result.emailAddress);
            Assert.AreEqual("second", result.emailAddress2);
            Assert.AreEqual("third", result.emailAddress3);
        }
        [Test]
        public void TestConvertPerson_TwoEmailAddresses()
        {
            var emailAddresses = new[] { "first", "second"};
            var person = new Person{};
            Array.ForEach(emailAddresses, person.EmailAddresses.Add);
            var result = m_PersonConverter.Convert(person);
            Assert.AreEqual("first", result.emailAddress);
            Assert.AreEqual("second", result.emailAddress2);
            Assert.IsTrue(string.IsNullOrEmpty(result.emailAddress3));
        }
        [Test]
        public void TestConvertPerson_OneEmailAddresses()
        {
            var emailAddresses = new[] { "first"};
            var person = new Person { };
            Array.ForEach(emailAddresses, person.EmailAddresses.Add);
            var result = m_PersonConverter.Convert(person);
            Assert.AreEqual("first", result.emailAddress);
            Assert.IsTrue(string.IsNullOrEmpty(result.emailAddress2));
            Assert.IsTrue(string.IsNullOrEmpty(result.emailAddress3));
        }
        [Test]
        public void TestConvert_NoEmailAddress()
        {
            var emailAddresses = new string[0];
            var person = new Person { };
            Array.ForEach(emailAddresses, person.EmailAddresses.Add);
            var result = m_PersonConverter.Convert(person);
            Assert.IsTrue(string.IsNullOrEmpty(result.emailAddress));
            Assert.IsTrue(string.IsNullOrEmpty(result.emailAddress2));
            Assert.IsTrue(string.IsNullOrEmpty(result.emailAddress3));
        }
    }
}